package node.servlet;

import hibernate.mappings.MsDoc;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import node.dao.CommonDao;

import org.hibernate.Hibernate;
import org.hibernate.type.Type;

import util.BaseServlet;
import util.Java2JsonUtil;
import util.Util;

public class DocServlet extends BaseServlet {

	protected void doBusiness() {
		String sort = request.getParameter("sort");
		System.out.println("sort:" + sort);
		 if ("docListData".equals(sort)) {
			docListData();
		}

	}

	private void docListData() {
		String nodeId = request.getParameter("nodeId");
		int start = Integer.parseInt(request.getParameter("start"));
		int pageSize = Util.getLimit(request);
		Object[] objs = { Integer.parseInt(nodeId) };
		Type[] types = { Hibernate.INTEGER };
		List<MsDoc> list = new CommonDao().getListForHibernate(
				"from MsDoc where nodeid=?", objs, types, start, pageSize);
		Map m=new HashMap();
		m.put("root", list);
		m.put("totalProperty",new CommonDao().getTotalForHibernate("select count(*) from MsDoc where nodeid=?", objs, types));
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/xml;charset=UTF-8");
		PrintWriter out = null;
		try {
			out = response.getWriter();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		out.println(Java2JsonUtil.toJson(m));
		out.close();
	}

	

}
